import os

import cv2
import numpy as np

from option import parse_args


def main():
    args = parse_args()
    # original_crops = os.path.join(args.root_dir, 'original_sequences', 'youtube', 'c23', 'diffs')
    # fake_diffs = os.path.join(args.root_dir, 'manipulated_sequences', args.fake_type, 'c23', 'diffs')
    diffs = os.path.join(args.root_dir, 'diffs')
    videos = open('abnormal_mean_statistics.dat').readlines()
    for video_name in videos:
        video_split = video_name.split(',')
        assert len(video_split) == 7

        diff_video_path = os.path.join(diffs, video_split[2])
        if os.path.exists(diff_video_path):
            for diff_name in os.listdir(diff_video_path):
                mask = cv2.imread(os.path.join(diff_video_path, diff_name), cv2.IMREAD_GRAYSCALE)
                # diff_name_split = diff_name.split('_')
                # assert len(diff_name_split) == 3
                # crop_name = '{}_{}.png'.format(diff_name_split[0], diff_name_split[1])
                if np.mean(mask) < 10.0 or np.mean(mask) > 50.0:
                    os.remove(os.path.join(diff_video_path, diff_name))
                    # os.remove(os.path.join(crop_video_path, crop_name))


if __name__ == '__main__':
    main()
